$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../lib"))
$:.unshift(File.expand_path(File.dirname(__FILE__)+"/../ext"))

require "test/unit"
begin
    require 'statsample'
    HAS_SS=true
rescue
    HAS_SS=false
end

if(HAS_GSL.nil?)
begin
    require 'rbgsl'
    HAS_GSL=true
rescue
    HAS_GSL=false
end
end

require "alglib"
require 'matrix'
class TestAlglib < Test::Unit::TestCase
    def test_linear_regression
        a=[1,3,2,4,3,5,4,6,5,7]
        b=[3,3,4,4,5,5,6,6,4,4]
        c=[11,22,30,40,50,65,78,79,99,100]
        y=[3,4,5,6,7,8,9,10,20,30]
        matrix=Matrix.columns([a,b,c,y])
        lr=Alglib::LinearRegression.build_from_matrix(matrix)
        assert_in_delta(0.695,lr.coeffs[0],0.001)
        assert_in_delta(11.027,lr.constant,0.001)
        assert_in_delta(1.785,lr.process([1,3,11]),0.001)
  end
  def test_array_to_real1darray
      v=[1,2,3]
      r1d=Alglib.array_to_real1darray(v)
      assert_equal(3,r1d.size)
      assert_equal(1,r1d[0])
      assert_equal(2,r1d[1])
      assert_equal(3,r1d[2])
  end
  def test_real2darray_to_array
      m=Matrix[[0,3,4],[1,2,5],[3,5,6]]
      v2=m.to_alglib_matrix
      m2=Alglib.real2darray_to_array(v2)
      assert_equal(3,m2.size)
      assert_equal([0,3,4],m2[0])
      assert_equal([1,2,5],m2[1])
      assert_equal([3,5,6],m2[2])
      end
end
